package com.webchat.pgc.controller;

import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.MessageCardTemplateRequestVO;
import com.webchat.domain.vo.response.MessageCardTemplateResponseVO;
import com.webchat.pgc.service.MessageCardTemplateService;
import com.webchat.rmi.pgc.MessageCardTemplateClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageCardTemplateController implements MessageCardTemplateClient {


    @Autowired
    private MessageCardTemplateService messageCardTemplateService;


    /**
     * 创建或更新服务号消息卡片模版配置
     *
     * @param templateRequest
     * @return
     */
    @Override
    public APIResponseBean<String> save(@RequestBody MessageCardTemplateRequestVO templateRequest) {

        templateRequest.validateTemplateParam();

        String templateId = messageCardTemplateService.save(templateRequest);
        return APIResponseBeanUtil.success(templateId);
    }

    /**
     * 查询模版详情
     *
     * @param templateId
     * @return
     */
    @Override
    public APIResponseBean<MessageCardTemplateResponseVO> template(@PathVariable String templateId) {
        MessageCardTemplateResponseVO messageCardTemplateResponse =
                                      messageCardTemplateService.get(templateId);
        return APIResponseBeanUtil.success(messageCardTemplateResponse);
    }
}
